using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region SurveyQuestion

	/// <summary>
	/// SurveyQuestion object for NHibernate mapped table 'SurveyQuestion'.
	/// </summary>
	[Serializable]
	public class SurveyQuestion : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _question;
		protected int _sort;
		protected string _type;
		protected bool _isEnable;
		protected string _applicationType;
		protected IList _surveyAnswers;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SurveyQuestion() { }

		public SurveyQuestion( string question, int sort, string type, bool isEnable, string applicationType )
		{
			this._question = question;
			this._sort = sort;
			this._type = type;
			this._isEnable = isEnable;
			this._applicationType = applicationType;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string Question
		{
			get { return _question; }
			set
			{
				if ( value != null && value.Length > 100)
					value = value.Substring(0, 100 );
				_question = value;
			}
		}

		public int Sort
		{
			get { return _sort; }
			set { _sort = value; }
		}

		public string Type
		{
			get { return _type; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Type", value, value.ToString());
				_type = value;
			}
		}

		public bool IsEnable
		{
			get { return _isEnable; }
			set { _isEnable = value; }
		}

		public string ApplicationType
		{
			get { return _applicationType; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for ApplicationType", value, value.ToString());
				_applicationType = value;
			}
		}

		public IList SurveyAnswers
		{
			get
			{
				if (_surveyAnswers==null)
				{
					_surveyAnswers = new ArrayList();
				}
				return _surveyAnswers;
			}
			set { _surveyAnswers = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is SurveyQuestion))
				throw new InvalidCastException("This object is not of type SurveyQuestion");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SurveyQuestion)obj).Id);
					break;
				case "Question":
					relativeValue = this.Question.CompareTo(((SurveyQuestion)obj).Question);
					break;
				case "Sort":
					relativeValue = this.Sort.CompareTo(((SurveyQuestion)obj).Sort);
					break;
				case "Type":
					relativeValue = this.Type.CompareTo(((SurveyQuestion)obj).Type);
					break;
				case "IsEnable":
					relativeValue = this.IsEnable.CompareTo(((SurveyQuestion)obj).IsEnable);
					break;
				case "ApplicationType":
						relativeValue = ( this.ApplicationType != null ) ? this.ApplicationType.CompareTo(((SurveyQuestion)obj).ApplicationType) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (SurveyQuestion.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
